<template>
  <div class="ai-robot font14">
     <p>{{$t('configLazyLoad.robotSeven.robotJumpTip1')}}<span @click="clickOpenFun" style="color: #459ae9;cursor: pointer">{{$t('configLazyLoad.robotSeven.robotJumpTip2')}}</span></p>
    <!--<el-button type="primary" class="primary_btn" @click.stop="openAI()">跳转到AI系统进行设置</el-button>-->
    <form  name="xbotSubmit" :action="xbotUrl" method="post" style="display:none;" target="_blank">
      <input type="text" v-for="(val, key, index) in page" :name="key" :value="val" :key="index"><br>
      <input type="submit" value="提交" id="xbotSubmit">
    </form>
  </div>
</template>

<script>
  import bus from '@/store/eventBus'
  export default {
    name: 'xbotRobotConfig',
    data () {
      return {
        url: '',
        page: '',
        xbotUrl: ''
      }
    },
    methods: {
      openXBot () {
        let user = this.$store.state.session.user
        const data = {
          account: user ? user.account : ''
        }
        this.$store.dispatch('xbotRobotConfig', data).then(res => {
          this.page = res.dict
          var lang = window.localStorage.lang || 'zh_CN'
          this.$set(this.page, 'lang', lang)
          this.xbotUrl = res.dict.xbotUrl
          this.getSubmitDom()
        })
      },
      clickOpenFun () {
        this.openXBot()
      },
      getSubmitDom () {
        this.$nextTick(function () {
          document.xbotSubmit.submit()
        })
      }
    },
    mounted () {
      bus.$on('openXbotRobot', () => {
        this.openXBot()
      })
      this.openXBot()
    },
    beforeDestroy () {
      bus.$off('openXbotRobot')
    }
  }
</script>

<style scoped lang="stylus">
  @import "./../../../../assets/common.styl"
  .ai-robot
    background $c-back
    text-align center
    margin 20px auto
</style>
